package com.shunda.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.shunda.common.core.domain.entity.SysOilPrice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shunda.common.annotation.Log;
import com.shunda.common.core.controller.BaseController;
import com.shunda.common.core.domain.AjaxResult;
import com.shunda.common.enums.BusinessType;
import com.shunda.system.service.ISysOilPriceService;
import com.shunda.common.utils.poi.ExcelUtil;
import com.shunda.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author shunda
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/system/oilPrice")
public class SysOilPriceController extends BaseController {
    @Autowired
    private ISysOilPriceService sysOilPriceService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysOilPrice sysOilPrice) {
        startPage();
        List<SysOilPrice> list = sysOilPriceService.selectSysOilPriceList(sysOilPrice);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOilPrice sysOilPrice) {
        List<SysOilPrice> list = sysOilPriceService.selectSysOilPriceList(sysOilPrice);
        ExcelUtil<SysOilPrice> util = new ExcelUtil<SysOilPrice>(SysOilPrice.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysOilPriceService.selectSysOilPriceById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOilPrice sysOilPrice) {
        Boolean flag = sysOilPriceService.checkRepetion(sysOilPrice);
        if(flag) {
            return toAjax(sysOilPriceService.insertSysOilPrice(sysOilPrice));
        }
        return AjaxResult.error("此加油站下已有本类型油品价格");
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOilPrice sysOilPrice) {
        return toAjax(sysOilPriceService.updateSysOilPrice(sysOilPrice));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysOilPriceService.deleteSysOilPriceByIds(ids));
    }
}
